﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes {
    import Engine.Managers.*;
    import Events.*;
    import Display.DialogUI.*;
    import Classes.util.*;
    import Classes.sim.*;
    import Classes.effects.*;
    import Modules.quest.Managers.*;
    import Display.*;

    public class TrainStation extends MapResource {

        private const TRAIN_STATION:String = "trainStation";
        protected const STATE_STATIC:String = "static";

        public function TrainStation(_arg1:String){
            super(_arg1);
            m_objectType = WorldObjectTypes.TRAIN_STATION;
            this.setState(this.STATE_STATIC);
            m_typeName = this.TRAIN_STATION;
            m_ownable = false;
        }
        override public function setState(_arg1:String):void{
            super.setState(_arg1);
            this.updateArrow();
        }
        public function forceUpdateArrow():void{
            this.updateArrow();
        }
        override protected function updateArrow():void{
            this.createStagePickEffect();
        }
        override protected function createStagePickEffect():void{
            var _local1:String;
            if (!Global.isVisiting()){
                if (Global.world.citySim.trainManager.isNeighborGated){
                    _local1 = StagePickEffect.PICK_LOCK;
                } else {
                    switch (Global.world.citySim.trainManager.trainState){
                        case TrainManager.TRAIN_STATE_IDLE_AWAY:
                            _local1 = StagePickEffect.PICK_ATTENTION;
                            break;
                        case TrainManager.TRAIN_STATE_DEPARTING:
                            _local1 = (Global.world.citySim.trainManager.isWaitingForTrain) ? StagePickEffect.PICK_IN_TRANSIT : StagePickEffect.PICK_ATTENTION;
                            break;
                        case TrainManager.TRAIN_STATE_EN_ROUTE:
                            _local1 = StagePickEffect.PICK_IN_TRANSIT;
                            break;
                        case TrainManager.TRAIN_STATE_AWAITING_CLEARANCE:
                            _local1 = StagePickEffect.PICK_TRAIN_AWAITING_CLEARANCE;
                            break;
                    };
                };
            };
            if (_local1){
                if (!m_stagePickEffect){
                    m_stagePickEffect = (MapResourceEffectFactory.createEffect(this, EffectType.STAGE_PICK) as StagePickEffect);
                    m_stagePickEffect.setPickType(_local1);
                    m_stagePickEffect.float();
                } else {
                    m_stagePickEffect.setPickType(_local1);
                    m_stagePickEffect.reattach();
                    m_stagePickEffect.float();
                };
            } else {
                removeStagePickEffect();
            };
        }
        override public function cleanUp():void{
            removeStagePickEffect();
            super.cleanUp();
        }
        override public function loadObject(_arg1:Object):void{
            super.loadObject(_arg1);
        }
        override public function isSellable():Boolean{
            return (false);
        }
        override public function canBeDragged():Boolean{
            return (false);
        }
        override protected function calculateDepthIndex():void{
            super.calculateDepthIndex();
            m_depthIndex = (m_depthIndex + (4 * 1000));
        }
        override public function onPlayAction():void{
            var _local1:GameQuest;
            var _local2:int;
            var _local3:int;
            var _local4:int;
            var _local5:String;
            var _local6:CharacterAdviceDialog;
            if (!Global.isVisiting()){
                if (Global.world.citySim.trainManager.isNeighborGated){
                    _local2 = Global.gameSettings.getInt("trainRequiredNeighbors", 0);
                    _local3 = Global.player.neighbors.length;
                    _local4 = Math.max(0, (_local2 - _local3));
                    _local5 = ((_local4)>1) ? "TrainUI_Neighbors_plural_text" : "TrainUI_Neighbors_singular_text";
                    _local6 = new CharacterAdviceDialog(ZLoc.t("Dialogs", _local5, {num:_local4}), "", GenericDialogView.TYPE_OK, this.onAddNeighborsDlgClosed, "TrainUI_Neighbors", null, true, 0, "TrainUI_Neighbors_button");
                    UI.displayPopup(_local6);
                    return;
                };
                StatsManager.sample(100, "trains", "clicked_station");
                _local1 = Global.questManager.getQuestByName(this.m_item.requiredQuestFlag);
                if (_local1){
                    if (!_local1.hasCompleted){
                        UI.displayMessage(ZLoc.t("Dialogs", "quest_train_unlocked"), GenericDialogView.TYPE_OK);
                        return;
                    };
                } else {
                    if (!Global.player.isQuestCompleted(this.m_item.requiredQuestFlag)){
                        UI.displayMessage(ZLoc.t("Dialogs", "quest_train_unlocked"), GenericDialogView.TYPE_OK);
                        return;
                    };
                };
                if (Global.world.citySim.trainManager.isWaitingForTrain){
                    Global.world.citySim.trainManager.showTrainStationDialog();
                } else {
                    Global.world.citySim.trainManager.showTrainScheduleCatalog();
                };
            };
        }
        protected function onAddNeighborsDlgClosed(_arg1:GenericPopupEvent):void{
            if (_arg1.button != GenericPopup.YES){
                return;
            };
            FrameManager.showTray("invite.php?ref=train_station");
        }
        override public function getToolTipStatus():String{
            var _local1 = "";
            if (!Global.isVisiting()){
                if (Global.world.citySim.trainManager.isWaitingForTrain){
                    _local1 = ZLoc.t("Dialogs", "TrainUI_TrainReturnTime", {time:GameUtil.formatMinutesSeconds(Global.world.citySim.trainManager.trainArrivalTime)});
                } else {
                    _local1 = ZLoc.t("Dialogs", "TrainUI_TrainReady");
                };
            };
            return (_local1);
        }
        override public function getToolTipAction():String{
            if (!Global.world.citySim.trainManager.isOrderAllowed){
                return (null);
            };
            var _local1:String;
            if (!Global.world.citySim.trainManager.isWaitingForTrain){
                _local1 = ZLoc.t("Dialogs", "TrainUI_TrainReadyAction");
            };
            return (_local1);
        }
        override public function get isHighlightable():Boolean{
            return (((((super.isHighlightable) && (!(Global.isVisiting())))) && (!(Global.world.citySim.trainManager.isNeighborGated))));
        }
        public function onNeighborAdded():void{
            this.updateArrow();
        }

    }
}//package Classes 
